TypeScript Partial ํ์ ์ ํ์ํ์ฌ ์ ํ์ ์์ฑ์ ๋ง๋ค๊ณ , ๊ฐ์ฒด ์กฐ์์ ๋จ์ํํ๋ฉฐ, ์ฝ๋ ์ ์ง ๊ด๋ฆฌ์ฑ์ ํฅ์์ํค๋ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ์ ์ค์ฉ์ ์ธ ์์ ์ ํจ๊ป ์์๋ณด์ธ์.
TypeScript Partial ํ์ ๋ง์คํฐํ๊ธฐ: ์ ์ฐ์ฑ์ ์ํ ์์ฑ ๋ณํ
์๋ฐ์คํฌ๋ฆฝํธ์ ์์ ์งํฉ์ธ ํ์
์คํฌ๋ฆฝํธ๋ ๋์ ์ธ ์น ๊ฐ๋ฐ ์ธ๊ณ์ ์ ์ ํ์ดํ์ ๋์
ํฉ๋๋ค. ๊ทธ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ ์ค ํ๋๋ Partial
ํ์
์ผ๋ก, ๊ธฐ์กด ํ์
์ ๋ชจ๋ ์์ฑ์ ์ ํ์ ์ผ๋ก ๋ง๋๋ ํ์
์ ์์ฑํ ์ ์๊ฒ ํด์ค๋๋ค. ์ด ๊ธฐ๋ฅ์ ๋ฐ์ดํฐ ์ฒ๋ฆฌ, ๊ฐ์ฒด ์กฐ์, API ์ํธ์์ฉ ์ ์์ฒญ๋ ์ ์ฐ์ฑ์ ์ ๊ณตํฉ๋๋ค. ์ด ๊ธ์์๋ Partial
ํ์
์ ์ฌ๋ ์๊ฒ ํ๊ตฌํ๊ณ , ํ์
์คํฌ๋ฆฝํธ ํ๋ก์ ํธ์์ ์ด๋ฅผ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ๊ธฐ ์ํ ์ค์ฉ์ ์ธ ์์ ์ ๋ชจ๋ฒ ์ฌ๋ก๋ฅผ ์ ๊ณตํฉ๋๋ค.
TypeScript Partial ํ์ ์ด๋ ๋ฌด์์ธ๊ฐ?
Partial<T>
ํ์
์ ํ์
์คํฌ๋ฆฝํธ์ ๋ด์ฅ ์ ํธ๋ฆฌํฐ ํ์
์
๋๋ค. ์ ๋ค๋ฆญ ์ธ์๋ก ํ์
T
๋ฅผ ๋ฐ์ T
์ ๋ชจ๋ ์์ฑ์ด ์ ํ์ ์ธ ์๋ก์ด ํ์
์ ๋ฐํํฉ๋๋ค. ๋ณธ์ง์ ์ผ๋ก, ๋ชจ๋ ์์ฑ์ required
(ํ์)์์ optional
(์ ํ)์ผ๋ก ๋ณํํ๋ฉฐ, ์ด๋ ํด๋น ํ์
์ ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ ๋ชจ๋ ์์ฑ์ด ๋ฐ๋์ ์กด์ฌํ ํ์๋ ์๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
๋ค์ ์์ ๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค:
interface User {
id: number;
name: string;
email: string;
country: string;
}
const user: User = {
id: 123,
name: "Alice",
email: "alice@example.com",
country: "USA",
};
์ด์ User
ํ์
์ Partial
๋ฒ์ ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค:
type PartialUser = Partial<User>;
const partialUser: PartialUser = {
name: "Bob",
};
const anotherPartialUser: PartialUser = {
id: 456,
email: "bob@example.com",
};
const emptyUser: PartialUser = {}; // ์ ํจํจ
์ด ์์ ์์ PartialUser
๋ id?
, name?
, email?
, country?
์์ฑ์ ๊ฐ์ง๋๋ค. ์ด๋ PartialUser
ํ์
์ ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ ์ด ์์ฑ๋ค์ ์ด๋ค ์กฐํฉ์ผ๋ก๋ ๋ง๋ค ์ ์์ผ๋ฉฐ, ์ฌ์ง์ด ์๋ฌด ์์ฑ๋ ํฌํจํ์ง ์์ ์๋ ์๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. emptyUser
ํ ๋น์ ์ด๋ฅผ ์ ๋ณด์ฌ์ฃผ๋ฉฐ, Partial
์ ํต์ฌ์ ์ธ ํน์ง์ธ ๋ชจ๋ ์์ฑ์ ์ ํ์ ์ผ๋ก ๋ง๋ ๋ค๋ ์ ์ ๊ฐ์กฐํฉ๋๋ค.
Partial ํ์ ์ ์ฌ์ฉํ๋ ์ด์ ๋ ๋ฌด์์ธ๊ฐ?
Partial
ํ์
์ ์ฌ๋ฌ ์๋๋ฆฌ์ค์์ ์ ์ฉํฉ๋๋ค:
- ๊ฐ์ฒด ์ ์ง์ ์
๋ฐ์ดํธ: ๊ธฐ์กด ๊ฐ์ฒด๋ฅผ ์
๋ฐ์ดํธํ ๋, ์ข
์ข
์ผ๋ถ ์์ฑ๋ง ์์ ํ๊ณ ์ถ์ ๋๊ฐ ์์ต๋๋ค.
Partial
์ ์ฌ์ฉํ๋ฉด ๋ณ๊ฒฝํ๋ ค๋ ์์ฑ๋ง์ผ๋ก ์ ๋ฐ์ดํธ ํ์ด๋ก๋๋ฅผ ์ ์ํ ์ ์์ต๋๋ค. - ์ ํ์ ๋งค๊ฐ๋ณ์: ํจ์ ๋งค๊ฐ๋ณ์์์
Partial
์ ์ฌ์ฉํ๋ฉด ํน์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ํ์ ์ผ๋ก ๋ง๋ค์ด ํจ์ ํธ์ถ ๋ฐฉ์์ ๋ ํฐ ์ ์ฐ์ฑ์ ์ ๊ณตํ ์ ์์ต๋๋ค. - ๋จ๊ณ๋ณ ๊ฐ์ฒด ๊ตฌ์ฑ: ๋ณต์กํ ๊ฐ์ฒด๋ฅผ ๊ตฌ์ฑํ ๋, ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ํ ๋ฒ์ ์ฌ์ฉํ ์ ์์ ์ ์์ต๋๋ค.
Partial
์ ์ฌ์ฉํ๋ฉด ๊ฐ์ฒด๋ฅผ ๋จ๊ณ์ ์ผ๋ก ๊ตฌ์ฑํ ์ ์์ต๋๋ค. - API ์์
: API๋ ์ข
์ข
ํน์ ํ๋๊ฐ ๋๋ฝ๋๊ฑฐ๋ null์ธ ๋ฐ์ดํฐ๋ฅผ ๋ฐํํฉ๋๋ค.
Partial
์ ์๊ฒฉํ ํ์ ๊ฐ์ ์์ด ์ด๋ฌํ ์ํฉ์ ์ํํ๊ฒ ์ฒ๋ฆฌํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค.
Partial ํ์ ์ ์ค์ฉ์ ์ธ ์์
1. ์ฌ์ฉ์ ํ๋กํ ์ ๋ฐ์ดํธ
์ฌ์ฉ์ ํ๋กํ์ ์ ๋ฐ์ดํธํ๋ ํจ์๊ฐ ์๋ค๊ณ ์์ํด ๋ณด์ธ์. ํจ์๊ฐ ๋งค๋ฒ ๋ชจ๋ ์ฌ์ฉ์ ์์ฑ์ ๋ฐ๋๋ก ์๊ตฌํ๋ ๋์ , ํน์ ํ๋์ ๋ํ ์ ๋ฐ์ดํธ๋ฅผ ํ์ฉํ๊ณ ์ถ์ ๊ฒ์ ๋๋ค.
interface UserProfile {
firstName: string;
lastName: string;
age: number;
country: string;
occupation: string;
}
function updateUserProfile(userId: number, updates: Partial<UserProfile>): void {
// ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์ฌ์ฉ์ ํ๋กํ์ ์
๋ฐ์ดํธํ๋ ๊ฒ์ ์๋ฎฌ๋ ์ด์
console.log(`์ฌ์ฉ์ ${userId}๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค:`, updates);
}
updateUserProfile(1, { firstName: "David" });
updateUserProfile(2, { lastName: "Smith", age: 35 });
updateUserProfile(3, { country: "Canada", occupation: "Software Engineer" });
์ด ๊ฒฝ์ฐ, Partial<UserProfile>
์ ์ฌ์ฉํ๋ฉด ํ์
์ค๋ฅ ์์ด ์
๋ฐ์ดํธ๊ฐ ํ์ํ ์์ฑ๋ง ์ ๋ฌํ ์ ์์ต๋๋ค.
2. API ์์ฒญ ๊ฐ์ฒด ์์ฑ
API ์์ฒญ์ ํ ๋, ์ ํ์ ๋งค๊ฐ๋ณ์๊ฐ ์์ ์ ์์ต๋๋ค. Partial
์ ์ฌ์ฉํ๋ฉด ์์ฒญ ๊ฐ์ฒด ์์ฑ์ ๋จ์ํํ ์ ์์ต๋๋ค.
interface SearchParams {
query: string;
category?: string;
location?: string;
page?: number;
pageSize?: number;
}
function searchItems(params: Partial<SearchParams>): void {
// API ํธ์ถ ์๋ฎฌ๋ ์ด์
console.log("๊ฒ์ ๋งค๊ฐ๋ณ์:", params);
}
searchItems({ query: "laptop" });
searchItems({ query: "phone", category: "electronics" });
searchItems({ query: "book", location: "London", page: 2 });
์ฌ๊ธฐ์ SearchParams
๋ ๊ฐ๋ฅํ ๊ฒ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ํฉ๋๋ค. Partial<SearchParams>
๋ฅผ ์ฌ์ฉํ์ฌ ํ์ํ ๋งค๊ฐ๋ณ์๋ง์ผ๋ก ์์ฒญ ๊ฐ์ฒด๋ฅผ ์์ฑํ ์ ์์ผ๋ฏ๋ก ํจ์๊ฐ ๋์ฑ ๋ค์ฉ๋๋ก ํ์ฉ๋ ์ ์์ต๋๋ค.
3. ํผ ๊ฐ์ฒด ์์ฑ
ํผ, ํนํ ๋ค๋จ๊ณ ํผ์ ๋ค๋ฃฐ ๋ Partial
์ ์ฌ์ฉํ๋ ๊ฒ์ ๋งค์ฐ ์ ์ฉํ ์ ์์ต๋๋ค. ํผ ๋ฐ์ดํฐ๋ฅผ Partial
๊ฐ์ฒด๋ก ํํํ๊ณ ์ฌ์ฉ์๊ฐ ํผ์ ์ฑ์๋๊ฐ์ ๋ฐ๋ผ ์ ์ง์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฑ์ธ ์ ์์ต๋๋ค.
interface AddressForm {
street: string;
city: string;
postalCode: string;
country: string;
}
let form: Partial<AddressForm> = {};
form.street = "123 Main St";
form.city = "Anytown";
form.postalCode = "12345";
form.country = "USA";
console.log("ํผ ๋ฐ์ดํฐ:", form);
์ด ์ ๊ทผ ๋ฐฉ์์ ํผ์ด ๋ณต์กํ๊ณ ์ฌ์ฉ์๊ฐ ๋ชจ๋ ํ๋๋ฅผ ํ ๋ฒ์ ์ฑ์ฐ์ง ์์ ์ ์์ ๋ ์ ์ฉํฉ๋๋ค.
๋ค๋ฅธ ์ ํธ๋ฆฌํฐ ํ์ ๊ณผ Partial ๊ฒฐํฉํ๊ธฐ
Partial
์ ๋ค๋ฅธ ํ์
์คํฌ๋ฆฝํธ ์ ํธ๋ฆฌํฐ ํ์
๊ณผ ๊ฒฐํฉํ์ฌ ๋ ๋ณต์กํ๊ณ ๋ง์ถคํ๋ ํ์
๋ณํ์ ๋ง๋ค ์ ์์ต๋๋ค. ์ ์ฉํ ์กฐํฉ ๋ช ๊ฐ์ง๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
Partial<Pick<T, K>>
: ํน์ ์์ฑ์ ์ ํ์ ์ผ๋ก ๋ง๋ญ๋๋ค.Pick<T, K>
๋T
์์ ์์ฑ์ ์ผ๋ถ๋ฅผ ์ ํํ๊ณ ,Partial
์ด ๊ทธ ์ ํ๋ ์์ฑ๋ค์ ์ ํ์ ์ผ๋ก ๋ง๋ญ๋๋ค.Required<Partial<T>>
: ์ง๊ด์ ๋ฐํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ผ ์ ์์ง๋ง, ๊ฐ์ฒด๊ฐ "์์ฑ"๋์์ ๋ ๋ชจ๋ ์์ฑ์ด ์กด์ฌํ๋์ง ํ์ธํ๋ ค๋ ์๋๋ฆฌ์ค์์ ์ ์ฉํฉ๋๋ค. ๊ฐ์ฒด๋ฅผ ๊ตฌ์ฑํ๋ ๋์Partial<T>
๋ก ์์ํ ๋ค์, ์ ์ฅํ๊ฑฐ๋ ์ฒ๋ฆฌํ๊ธฐ ์ ์Required<Partial<T>>
๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ ํ๋๊ฐ ์ฑ์์ก๋์ง ๊ฒ์ฆํ ์ ์์ต๋๋ค.Readonly<Partial<T>>
: ๋ชจ๋ ์์ฑ์ด ์ ํ์ ์ด๊ณ ์ฝ๊ธฐ ์ ์ฉ์ธ ํ์ ์ ๋ง๋ญ๋๋ค. ์ด๋ ๋ถ๋ถ์ ์ผ๋ก ์ฑ์์ง ์ ์์ง๋ง ์ด๊ธฐ ์์ฑ ํ์๋ ์์ ๋์ด์๋ ์ ๋๋ ๊ฐ์ฒด๋ฅผ ์ ์ํด์ผ ํ ๋ ์ ์ฉํฉ๋๋ค.
์์ : Partial๊ณผ Pick ํจ๊ป ์ฌ์ฉํ๊ธฐ
์
๋ฐ์ดํธ ์ค์ User
์ ํน์ ์์ฑ๋ง ์ ํ์ ์ผ๋ก ๋ง๋ค๊ณ ์ถ๋ค๊ณ ๊ฐ์ ํด ๋ด
์๋ค. Partial<Pick<User, 'name' | 'email'>>
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
interface User {
id: number;
name: string;
email: string;
country: string;
}
type NameEmailUpdate = Partial<Pick<User, 'name' | 'email'>>;
const update: NameEmailUpdate = {
name: "Charlie",
// country๋ ์ฌ๊ธฐ์ ํ์ฉ๋์ง ์์, name๊ณผ email๋ง ๊ฐ๋ฅ
};
const update2: NameEmailUpdate = {
email: "charlie@example.com"
};
Partial ํ์ ์ฌ์ฉ ์ ๋ชจ๋ฒ ์ฌ๋ก
- ์ฃผ์ํด์ ์ฌ์ฉํ๊ธฐ:
Partial
์ ์ ์ฐ์ฑ์ ์ ๊ณตํ์ง๋ง, ๋จ์ฉํ๋ฉด ํ์ ๊ฒ์ฌ๊ฐ ๋์จํด์ ธ ์ ์ฌ์ ์ธ ๋ฐํ์ ์ค๋ฅ๋ก ์ด์ด์ง ์ ์์ต๋๋ค. ์ง์ ์ผ๋ก ์ ํ์ ์์ฑ์ด ํ์ํ ๋๋ง ์ฌ์ฉํ์ธ์. - ๋์ ๊ณ ๋ คํ๊ธฐ:
Partial
์ ์ฌ์ฉํ๊ธฐ ์ ์, ์ ๋์ธ ํ์ ์ด๋ ์ธํฐํ์ด์ค์ ์ง์ ์ ์๋ ์ ํ์ ์์ฑ ๊ฐ์ ๋ค๋ฅธ ๊ธฐ์ ์ด ๋ ์ ์ ํ ์ง ํ๊ฐํด ๋ณด์ธ์. - ๋ช
ํํ๊ฒ ๋ฌธ์ํํ๊ธฐ:
Partial
์ ์ฌ์ฉํ ๋๋ ์ ์ฌ์ฉ๋๋์ง, ์ด๋ค ์์ฑ์ด ์ ํ์ ์ผ๋ก ์์๋๋์ง๋ฅผ ๋ช ํํ๊ฒ ๋ฌธ์ํํ์ธ์. ์ด๋ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค์ด ์๋๋ฅผ ์ดํดํ๊ณ ์ค์ฉ์ ํผํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค. - ๋ฐ์ดํฐ ๊ฒ์ฆํ๊ธฐ:
Partial
์ ์์ฑ์ ์ ํ์ ์ผ๋ก ๋ง๋ค๋ฏ๋ก, ์๊ธฐ์น ์์ ๋์์ ๋ฐฉ์งํ๊ธฐ ์ํด ์ฌ์ฉํ๊ธฐ ์ ์ ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ฆํด์ผ ํฉ๋๋ค. ํ์ ๊ฐ๋๋ ๋ฐํ์ ๊ฒ์ฌ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ํ ๋ ํ์ ์์ฑ์ด ์กด์ฌํ๋์ง ํ์ธํ์ธ์. - ๋น๋ ํจํด ์ฌ์ฉ ๊ณ ๋ คํ๊ธฐ: ๋ณต์กํ ๊ฐ์ฒด ์์ฑ์ ๊ฒฝ์ฐ, ๋น๋ ํจํด์ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ๋ง๋๋ ๊ฒ์ ๊ณ ๋ คํด ๋ณด์ธ์. ์ด๋ ์ข ์ข `Partial`์ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ์ ์ง์ ์ผ๋ก ๊ตฌ์ฑํ๋ ๊ฒ๋ณด๋ค ๋ ๋ช ํํ๊ณ ์ ์ง ๊ด๋ฆฌํ๊ธฐ ์ฌ์ด ๋์์ด ๋ ์ ์์ต๋๋ค.
์ ์ธ๊ณ์ ๊ณ ๋ ค์ฌํญ ๋ฐ ์์
๊ธ๋ก๋ฒ ์ ํ๋ฆฌ์ผ์ด์
์ ์์
ํ ๋, ์ฌ๋ฌ ์ง์ญ๊ณผ ๋ฌธํ์ ๋งฅ๋ฝ์ ๊ฑธ์ณ Partial
ํ์
์ ์ด๋ป๊ฒ ํจ๊ณผ์ ์ผ๋ก ์ฌ์ฉํ ์ ์๋์ง ๊ณ ๋ คํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
์์ : ๊ตญ์ ์ฃผ์ ์์
์ฃผ์ ํ์์ ๋๋ผ๋ง๋ค ํฌ๊ฒ ๋ค๋ฆ
๋๋ค. ์ผ๋ถ ๊ตญ๊ฐ์์๋ ํน์ ์ฃผ์ ๊ตฌ์ฑ ์์๋ฅผ ์๊ตฌํ๋ ๋ฐ๋ฉด, ๋ค๋ฅธ ๊ตญ๊ฐ์์๋ ๋ค๋ฅธ ์ฐํธ๋ฒํธ ์์คํ
์ ์ฌ์ฉํฉ๋๋ค. Partial
์ ์ฌ์ฉํ๋ฉด ์ด๋ฌํ ์ฐจ์ด๋ฅผ ์์ฉํ ์ ์์ต๋๋ค.
interface InternationalAddress {
streetAddress: string;
apartmentNumber?: string; // ์ผ๋ถ ๊ตญ๊ฐ์์๋ ์ ํ ์ฌํญ
city: string;
region?: string; // ์ฃผ, ๋ ๋ฑ
postalCode: string;
country: string;
addressFormat?: string; // ๊ตญ๊ฐ์ ๋ฐ๋ผ ํ์ ํ์์ ์ง์ ํ๊ธฐ ์ํจ
}
function formatAddress(address: InternationalAddress): string {
let formattedAddress = "";
switch (address.addressFormat) {
case "UK":
formattedAddress = `${address.streetAddress}\n${address.city}\n${address.postalCode}\n${address.country}`;
break;
case "USA":
formattedAddress = `${address.streetAddress}\n${address.city}, ${address.region} ${address.postalCode}\n${address.country}`;
break;
case "Japan":
formattedAddress = `${address.postalCode}\n${address.region}${address.city}\n${address.streetAddress}\n${address.country}`;
break;
default:
formattedAddress = `${address.streetAddress}\n${address.city}\n${address.postalCode}\n${address.country}`;
}
return formattedAddress;
}
const ukAddress: Partial<InternationalAddress> = {
streetAddress: "10 Downing Street",
city: "London",
postalCode: "SW1A 2AA",
country: "United Kingdom",
addressFormat: "UK"
};
const usaAddress: Partial<InternationalAddress> = {
streetAddress: "1600 Pennsylvania Avenue NW",
city: "Washington",
region: "DC",
postalCode: "20500",
country: "USA",
addressFormat: "USA"
};
console.log("์๊ตญ ์ฃผ์:\n", formatAddress(ukAddress as InternationalAddress));
console.log("๋ฏธ๊ตญ ์ฃผ์:\n", formatAddress(usaAddress as InternationalAddress));
InternationalAddress
์ธํฐํ์ด์ค๋ ์ ์ธ๊ณ์ ๋ค์ํ ์ฃผ์ ํ์์ ์์ฉํ๊ธฐ ์ํด apartmentNumber
๋ฐ region
๊ณผ ๊ฐ์ ์ ํ์ ํ๋๋ฅผ ํ์ฉํฉ๋๋ค. addressFormat
ํ๋๋ ๊ตญ๊ฐ์ ๋ฐ๋ผ ์ฃผ์๊ฐ ํ์๋๋ ๋ฐฉ์์ ์ฌ์ฉ์ ์ ์ํ๋ ๋ฐ ์ฌ์ฉ๋ ์ ์์ต๋๋ค.
์์ : ์ง์ญ๋ณ ์ฌ์ฉ์ ํ๊ฒฝ ์ค์
์ฌ์ฉ์ ํ๊ฒฝ ์ค์ ์ ์ง์ญ์ ๋ฐ๋ผ ๋ค๋ฅผ ์ ์์ต๋๋ค. ์ผ๋ถ ์ค์ ์ ํน์ ๊ตญ๊ฐ๋ ๋ฌธํ๊ถ์์๋ง ๊ด๋ จ์ด ์์ ์ ์์ต๋๋ค.
interface UserPreferences {
darkMode: boolean;
language: string;
currency: string;
timeZone: string;
pushNotificationsEnabled: boolean;
smsNotificationsEnabled?: boolean; // ์ผ๋ถ ์ง์ญ์์๋ ์ ํ ์ฌํญ
marketingEmailsEnabled?: boolean;
regionSpecificPreference?: any; // ์ ์ฐํ ์ง์ญ๋ณ ์ค์
}
function updateUserPreferences(userId: number, preferences: Partial<UserPreferences>): void {
// ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์ฌ์ฉ์ ํ๊ฒฝ ์ค์ ์
๋ฐ์ดํธ ์๋ฎฌ๋ ์ด์
console.log(`์ฌ์ฉ์ ${userId}์ ํ๊ฒฝ ์ค์ ์
๋ฐ์ดํธ:`, preferences);
}
updateUserPreferences(1, {
darkMode: true,
language: "en-US",
currency: "USD",
timeZone: "America/Los_Angeles"
});
updateUserPreferences(2, {
darkMode: false,
language: "fr-CA",
currency: "CAD",
timeZone: "America/Toronto",
smsNotificationsEnabled: true // ์บ๋๋ค์์๋ ํ์ฑํ๋จ
});
UserPreferences
์ธํฐํ์ด์ค๋ ํน์ ์ง์ญ์์๋ง ๊ด๋ จ์ด ์์ ์ ์๋ smsNotificationsEnabled
๋ฐ marketingEmailsEnabled
์ ๊ฐ์ ์ ํ์ ์์ฑ์ ์ฌ์ฉํฉ๋๋ค. regionSpecificPreference
ํ๋๋ ์ง์ญ๋ณ ์ค์ ์ ์ถ๊ฐํ๊ธฐ ์ํ ์ถ๊ฐ์ ์ธ ์ ์ฐ์ฑ์ ์ ๊ณตํฉ๋๋ค.
๊ฒฐ๋ก
ํ์
์คํฌ๋ฆฝํธ์ Partial
ํ์
์ ์ ์ฐํ๊ณ ์ ์ง ๊ด๋ฆฌํ๊ธฐ ์ฌ์ด ์ฝ๋๋ฅผ ์์ฑํ๊ธฐ ์ํ ๋ค์ฌ๋ค๋ฅํ ๋๊ตฌ์
๋๋ค. ์ ํ์ ์์ฑ์ ์ ์ํ ์ ์๊ฒ ํจ์ผ๋ก์จ ๊ฐ์ฒด ์กฐ์, API ์ํธ์์ฉ, ๋ฐ์ดํฐ ์ฒ๋ฆฌ๋ฅผ ๋จ์ํํฉ๋๋ค. Partial
์ ํจ๊ณผ์ ์ผ๋ก ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๊ณผ ๋ค๋ฅธ ์ ํธ๋ฆฌํฐ ํ์
๊ณผ์ ์กฐํฉ์ ์ดํดํ๋ฉด ํ์
์คํฌ๋ฆฝํธ ๊ฐ๋ฐ ์ํฌํ๋ก์ฐ๋ฅผ ํฌ๊ฒ ํฅ์์ํฌ ์ ์์ต๋๋ค. ์ ์ฌ์ ์ธ ํจ์ ์ ํผํ๊ธฐ ์ํด ์ ์คํ๊ฒ ์ฌ์ฉํ๊ณ , ๋ชฉ์ ์ ๋ช
ํํ ๋ฌธ์ํํ๋ฉฐ, ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ฆํ๋ ๊ฒ์ ์์ง ๋ง์ธ์. ๊ธ๋ก๋ฒ ์ ํ๋ฆฌ์ผ์ด์
์ ๊ฐ๋ฐํ ๋๋ ๋ค์ํ ์ง์ญ๊ณผ ๋ฌธํ์ ์๊ตฌ์ฌํญ์ ๊ณ ๋ คํ์ฌ Partial
ํ์
์ ํ์ฉํด ์ ์์ฑ ์๊ณ ์ฌ์ฉ์ ์นํ์ ์ธ ์๋ฃจ์
์ ๋ง๋์ธ์. Partial
ํ์
์ ๋ง์คํฐํจ์ผ๋ก์จ, ๋ค์ํ ์๋๋ฆฌ์ค๋ฅผ ์ฐ์ํ๊ณ ์ ๋ฐํ๊ฒ ์ฒ๋ฆฌํ ์ ์๋ ๋ ๊ฒฌ๊ณ ํ๊ณ , ์ ์์ฑ ์์ผ๋ฉฐ, ์ ์ง ๊ด๋ฆฌํ๊ธฐ ์ฌ์ด ํ์
์คํฌ๋ฆฝํธ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.